<template>
  <view>

    <wait ref="waitRef" :goodsInfoList="goodsInfoList" />

    <view style="height: 80px;"></view>

    <view
      class="flex-block p-10"
      style="position: fixed; bottom: 0; left: 0; z-index: 999; background-color: #ffffff; width: 100%; box-sizing: border-box;"
      >
      <view style="flex: 1">
        <up-button size="normal" :color="$u.color.mainColor" @click="submit">创建订单</up-button>
      </view>
    </view>
  </view>
</template>

<script>
import wait from './wait.vue'
import { useSeckillStore } from '@/stores/seckill'
export default {
  components: { wait },
  data() {
    return {
      baseData: {},
      seckillStore: useSeckillStore()
    }
  },
  computed: {
    goodsInfoList() {
      return this.baseData.goodsInfo
    }
  },
  mounted() {
    this.baseData = this.seckillStore.seckillInfo
  },
  methods: {
    async submit() {
      let params = {
        "activityId": this.baseData.activityId,
        "storeId": this.$refs.waitRef.model1.store.id,
        "addressId": this.$refs.waitRef.model1.address.id,
        "remark": this.$refs.waitRef.formData.remark,
        "delivery": 1,
        "expressFeeId": this.$refs.waitRef.model1.expressTime.id,
        "items": [
          {
            "id": this.baseData.goodsInfo[0].id,
            "quantity": this.baseData.goodsInfo[0].quantity
          }
        ]
        }
      let { code, data } = await this.$api.activity.seckillTrade(params)
      if (code == 200) {
        uni.showToast({
          title: '下单成功',
          icon: 'none'
        })
        uni.navigateTo({ url: `/pages/create-order/create-order?id=${data.tradeId}&type=pay` })
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
:deep(.u-form-item__body)
  padding 15px 0
</style>